package com.hyny.framework.platform.system.sucurity;

import com.hyny.framework.base.redis.RedisEnum;
import com.hyny.framework.base.redis.RedisUtil;
import com.hyny.framework.platform.system.utils.SecurityUtil;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Configuration
public class CustomLogoutHandler implements LogoutHandler {

    /**
     * Redis工具类
     */
    @Autowired
    private RedisUtil redisUtil;

    @SneakyThrows
    @Override
    public void logout(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) {
        // 移除Redis中的用户登录信息
        redisUtil.removeString(RedisEnum.LOGIN_INFO, SecurityUtil.getUserId().toString());
    }
}
